#!/usr/bin/python

# If program is run, will change terminal colour based on argv
# Also has a library of colour chars and a colourise function

import sys

class Colour(object):
    colours = {"black":0, "red":1, "green":2, "yellow":3, "blue":4, "magenta":5, "cyan":6, "white":7}
    def __init__(self, colour):
        self.number = colours[colour]

def charCode(index):
    return "\033[" + str(index) + "m"
        
def colourise(text, colour, fg = True, bg = False):
    # colourise a string, by default foreground only
    try:
        if fg:
            return charCode(30 + colour.number) + text + charCode(0)
        if bg:
            return charCode(40 + colour.number) + text + charCode(0)
    except AttributeError:
        print("Colour must be of type ansi.Colour")
        raise AttributeError
        
if __name__ == "__main__":
    # instantly update terminal colour with given index
    sys.stdout.write("\033[" + sys.argv[1] + "m")


# colours
black = Colour("black")
red = Colour("red")
green = Colour("green")
yellow = Colour("yellow")
blue = Colour("blue")
magenta = Colour("magenta")
cyan = Colour("cyan")
white = Colour("white")

# chess pieces
king = u"\u2654"
queen = u"\u2655"
rook = u"\u2656"
bishop = u"\u2657"
knight = u"\u2658"
pawn = u"\u2659"
blank = " "